import router from '../../router'
import Router from 'vue-router'
import store from '../../vuex/store'
const constantRoutes = store.state.constantRoutes

function lazyLoading(url) {
  return () => import(`@/components/page/${url}`)
}


function routeGuard(isTrue) {
  store.dispatch("SET_MENULIST");
  const createRouter = () => new Router({
    // mode: 'history', // 去掉url中的#
    base: process.env.BASE_URL,
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes
  })
  const newRouter = createRouter()
  console.log(newRouter)
  // 初始化之后的matcher替换当前router的matcher
  router.matcher = newRouter.matcher // the relevant part

  router.addRoutes(store.state.newRoutes); //添加路由
  // console.log('store.state.menuList', store.state.newRoutes, isTrue)
  if (
    isTrue
  ) {
    //缓存已有登录信息跳转

    router.push(store.state.newRoutes[0].path);
  }


  //   window.location.reload()
  // router.beforeEach(async (to, from, next) => {
  //   console.log(to,from,next)
  // })
  // router.afterEach((to, from, next) => {
  //   console.log(to,from,next)
  // })
}
export {
  routeGuard
}
